package com.ms.auction.auth.oauth2.service;

import com.google.common.collect.Lists;
import com.ms.auction.auth.system.entity.TbPermission;
import com.ms.auction.auth.system.entity.TbUser;
import com.ms.auction.auth.system.service.ITbPermissionService;
import com.ms.auction.auth.system.service.ITbUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@Service
public class PhoneUserDetailService extends AbstractUserDetailService {

    @Override
    protected  TbUser getUser(String phone) {
        // 手机验证码调用FeignClient根据电话号码查询用户
        TbUser tbUser= tbUserService.getByUsername(phone);
        if(tbUser == null){
            log.error("找不到该用户，手机号码：" + phone);
            throw new UsernameNotFoundException("找不到该用户，手机号码：" + phone);
        }
        return tbUser;
    }

}
